package com.zyl.pts.web.controller;

import com.zyl.pts.config.anno.SystemLog;
import com.zyl.pts.config.enums.CodeAndMessageEnum;
import com.zyl.pts.config.result.Result;
import com.zyl.pts.domain.dto.FHDTO.FHUpdateOrAddDTO;
import com.zyl.pts.service.FHService;
import com.zyl.pts.utils.CUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @version v1.0
 * @ProjectName: product_source
 * @Package: com.zyl.pts.web.controller
 * @ClassName: FHController
 * @Description TODO(栏舍管理模块)
 * @Author 翟玉龙
 * @Date 2024/11/19-15:27
 */
@Tag(name = "栏舍管理", description = "栏舍管理")
@RestController
@RequestMapping("/fenceHouse")
public class FHController {

    private final FHService fhService;

    public FHController(FHService fhService) {
        this.fhService = fhService;
    }

    /**
     * 分页多条件查询栏舍信息接口
     * @param pageNum 页码
     * @param pageSize 页面大小
     * @param fhName 栏舍名称，支持模糊查询
     * @return {@link Result }<{@link ? }>
     */
    @SystemLog(business = "分页多条件查询栏舍信息接口")
    @Operation(summary = "分页多条件查询栏舍信息接口")
    @GetMapping("/query")
    public Result<?> getFenceHouseList(
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pageSize", defaultValue = "2") Integer pageSize,
            @RequestParam(value = "fhName", required = false) String fhName
    ) {
        return Result.success(
                CodeAndMessageEnum.SUCCESS,
                fhService.getFenceHouseList(pageNum, pageSize, fhName)
        );
    }

    /**
     * 根据栏舍编号查询栏舍信息以及栏圈信息接口
     * @param fhId 栏舍编号
     * @return {@link Result }<{@link ? }>
     */
    @SystemLog(business = "根据栏舍编号查询栏舍信息以及栏圈信息接口")
    @Operation(summary = "根据栏舍编号查询栏舍信息以及栏圈信息接口")
    @GetMapping("/selectById")
    public Result<?> getFenceHouseDetail(
            @RequestParam(value = "fhId") String fhId
    ) {
        return Result.success(
                CodeAndMessageEnum.SUCCESS,
                fhService.getFenceHouseById(fhId)
        );
    }

    /**
     * 新增或修改栏舍接口
     * @param updateOrAdd 栏舍信息
     * @return {@link Result }<{@link ? }>
     */
    @SystemLog(business = "新增或修改栏舍接口")
    @Operation(summary = "新增或修改栏舍接口")
    @PostMapping("/saveOrUpdate")
    public Result<?> saveOrUpdateFenceHouse(
            @RequestBody @Validated FHUpdateOrAddDTO updateOrAdd
    ) {
        return Result.success(
                fhService.addOrUpdateFenceHouse(updateOrAdd)
        );
    }

    /**
     * 根据id删除栏舍信息接口
     * @param hId 栏舍编号
     * @return {@link Result }<{@link ? }>
     */
    @SystemLog(business = "根据id删除栏舍信息接口")
    @Operation(summary = "根据id删除栏舍信息接口")
    @DeleteMapping("/deleteById/{hId}")
    public Result<?> deleteFenceHouseById(
            @PathVariable String hId
    ) {
        return Result.success(
                fhService.deleteFenceHouseById(hId)
        );
    }

    /**
     * 批量删除栏舍
     * @param hIds 栏舍编号列表
     * @return {@link Result }<{@link ? }>
     */
    @SystemLog(business = "批量删除栏舍")
    @Operation(summary = "批量删除栏舍")
    @DeleteMapping("/deleteByIdAll")
    public Result<?> deleteFenceHouseByIds(
            @RequestBody List<String> hIds
    ) {
        CUtil.logInfo(hIds.toString());
        return Result.success(
                fhService.deleteFenceHouseByIdList(hIds)
        );
    }
}
